{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2a516963",
   "metadata": {},
   "source": [
    "# 用于RT6755"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1ce8148",
   "metadata": {},
   "outputs": [],
   "source": [
    "from OpticalSensor import CA410Sensor as EyeSensor\n",
    "\n",
    "import time\n",
    "\n",
    "#from jtlib import *\n",
    "import jtoollib as jt\n",
    "from pic_window import *"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f52f09d8",
   "metadata": {},
   "source": [
    "# VOP测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b2478fa4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "455.84806\n",
      "474.57925\n",
      "491.81919\n",
      "507.49205\n",
      "522.09235\n",
      "535.22968\n",
      "547.28788\n",
      "558.25614\n",
      "568.02592\n",
      "576.92381\n",
      "584.9247\n",
      "591.90596\n",
      "598.12668\n",
      "603.54372\n",
      "608.38492\n",
      "612.44489\n",
      "615.83015\n",
      "618.72326\n",
      "621.01428\n",
      "622.82793\n",
      "624.14464\n",
      "625.03551\n",
      "625.61066\n",
      "625.75136\n",
      "625.63874\n",
      "625.15124\n",
      "624.43138\n",
      "623.46904\n",
      "622.24579\n",
      "620.90136\n",
      "619.3315\n"
     ]
    }
   ],
   "source": [
    "# 1. 实例化传感器对象（根据实际串口号和波特率修改）\n",
    "sensor = EyeSensor(port='COM13')\n",
    "\n",
    "y_list = []\n",
    "\n",
    "# 扫描JI2C\n",
    "devices = jt.scan_devices_sn()\n",
    "# 开启JI2C\n",
    "handle = jt.open_device(devices[0])\n",
    "\n",
    "win = NonBlockingImageWindow(\"Demo\", size=(800, 800), fps=10)\n",
    "# RGB数据\n",
    "img = np.zeros((800, 800, 3), dtype=np.uint8)\n",
    "img[:, :, :] = 255\n",
    "win.update(img, fmt=\"rgb\")\n",
    "\n",
    "try:\n",
    "    sensor.XYZmode()\n",
    "    \n",
    "    # RT6755解锁码\n",
    "    jt.i2c_write(handle=handle, addr=0x46, reg=0x00, data=[ 0x65, 0x9A])\n",
    "\n",
    "    # 配置Gam1 Gam2为 AVDD-0.2V/AVEE+0.2V\n",
    "    jt.i2c_write(handle=handle, addr=0x46, reg=0x0E, data=[ 0x0A])\n",
    "    jt.i2c_write(handle=handle, addr=0x46, reg=0x0F, data=[ 0x0A])\n",
    "\n",
    "    # 遍历AVDD/AVEE ±4~±7V，使VOP输出±3.8-±6.8\n",
    "    for i in range(31):\n",
    "        # AVDD\n",
    "        jt.i2c_write(handle=handle, addr=0x46, reg=0x05, data=[ i*2])\n",
    "        # AVEE\n",
    "        jt.i2c_write(handle=handle, addr=0x46, reg=0x06, data=[ i])\n",
    "\n",
    "        time.sleep(0.5)\n",
    "\n",
    "        flag = True\n",
    "        while flag:\n",
    "            try:\n",
    "                x_val, y_val, z_val = sensor.GetXYZ()\n",
    "                flag = False\n",
    "            except:\n",
    "                pass\n",
    "\n",
    "        y_list.append(y_val)\n",
    "        print(y_val)\n",
    "\n",
    "finally:\n",
    "    jt.jtool.DevClose(handle)\n",
    "    win.stop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c140ad0c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
